<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>1.3 openxlsx | 商业数据分析师-R 语言数据处理</title>
  <meta name="description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  <meta name="generator" content="bookdown 0.22 and GitBook 2.6.7" />

  <meta property="og:title" content="1.3 openxlsx | 商业数据分析师-R 语言数据处理" />
  <meta property="og:type" content="book" />
  
  
  <meta property="og:description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="1.3 openxlsx | 商业数据分析师-R 语言数据处理" />
  
  <meta name="twitter:description" content="商业数据分析师的 R 语言学习笔记,主要集中在数据清洗相关包的介绍，从数据导入(本地数据 数据库)到数据清洗，到固定报表输出的自动化流程。" />
  

<meta name="author" content="Yufei Zhong" />


<meta name="date" content="2021-06-23" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="writexl.html"/>
<link rel="next" href="readr-package.html"/>
<script src="libs/header-attrs-2.8/header-attrs.js"></script>
<script src="libs/jquery-3.5.1/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />









<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<link href="libs/tabwid-1.0.0/tabwid.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.5.3/htmlwidgets.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.18/datatables.js"></script>
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk-1.1.1/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.1.1/js/crosstalk.min.js"></script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>


<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">R学习笔记</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>欢迎</a>
<ul>
<li class="chapter" data-level="" data-path="abstract.html"><a href="abstract.html"><i class="fa fa-check"></i>内容概要</a></li>
<li class="chapter" data-level="" data-path="sec-licenses.html"><a href="sec-licenses.html"><i class="fa fa-check"></i>授权说明</a></li>
<li class="chapter" data-level="" data-path="session.html"><a href="session.html"><i class="fa fa-check"></i>运行信息</a></li>
<li class="chapter" data-level="" data-path="author.html"><a href="author.html"><i class="fa fa-check"></i>关于本人</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="data-read-write-description.html"><a href="data-read-write-description.html"><i class="fa fa-check"></i><b>1</b> 数据导入导出</a>
<ul>
<li class="chapter" data-level="1.1" data-path="readxl-description.html"><a href="readxl-description.html"><i class="fa fa-check"></i><b>1.1</b> readxl</a>
<ul>
<li class="chapter" data-level="1.1.1" data-path="readxl-description.html"><a href="readxl-description.html#readxl:install"><i class="fa fa-check"></i><b>1.1.1</b> 安装</a></li>
<li class="chapter" data-level="1.1.2" data-path="readxl-description.html"><a href="readxl-description.html#readxl:usage"><i class="fa fa-check"></i><b>1.1.2</b> 用法</a></li>
<li class="chapter" data-level="1.1.3" data-path="readxl-description.html"><a href="readxl-description.html#batch:read"><i class="fa fa-check"></i><b>1.1.3</b> 批量读取</a></li>
<li class="chapter" data-level="1.1.4" data-path="readxl-description.html"><a href="readxl-description.html#batch:write"><i class="fa fa-check"></i><b>1.1.4</b> 批量输出</a></li>
</ul></li>
<li class="chapter" data-level="1.2" data-path="writexl.html"><a href="writexl.html"><i class="fa fa-check"></i><b>1.2</b> writexl</a>
<ul>
<li class="chapter" data-level="1.2.1" data-path="writexl.html"><a href="writexl.html#writexl:usage"><i class="fa fa-check"></i><b>1.2.1</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path="openxlsx-description.html"><a href="openxlsx-description.html"><i class="fa fa-check"></i><b>1.3</b> openxlsx</a>
<ul>
<li class="chapter" data-level="1.3.1" data-path="openxlsx-description.html"><a href="openxlsx-description.html#openxlsx:install"><i class="fa fa-check"></i><b>1.3.1</b> 安装</a></li>
<li class="chapter" data-level="1.3.2" data-path="openxlsx-description.html"><a href="openxlsx-description.html#openxlsx:functions"><i class="fa fa-check"></i><b>1.3.2</b> 基础功能</a></li>
<li class="chapter" data-level="1.3.3" data-path="openxlsx-description.html"><a href="openxlsx-description.html#定制格式输出"><i class="fa fa-check"></i><b>1.3.3</b> 定制格式输出</a></li>
<li class="chapter" data-level="1.3.4" data-path="openxlsx-description.html"><a href="openxlsx-description.html#函数参数"><i class="fa fa-check"></i><b>1.3.4</b> 函数参数</a></li>
<li class="chapter" data-level="1.3.5" data-path="openxlsx-description.html"><a href="openxlsx-description.html#总结"><i class="fa fa-check"></i><b>1.3.5</b> 总结</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path="readr-package.html"><a href="readr-package.html"><i class="fa fa-check"></i><b>1.4</b> readr</a>
<ul>
<li class="chapter" data-level="1.4.1" data-path="readr-package.html"><a href="readr-package.html#readr:install"><i class="fa fa-check"></i><b>1.4.1</b> 安装</a></li>
<li class="chapter" data-level="1.4.2" data-path="readr-package.html"><a href="readr-package.html#readr:usage"><i class="fa fa-check"></i><b>1.4.2</b> 用法</a></li>
<li class="chapter" data-level="1.4.3" data-path="readr-package.html"><a href="readr-package.html#readr:write-function"><i class="fa fa-check"></i><b>1.4.3</b> 导出功能</a></li>
<li class="chapter" data-level="1.4.4" data-path="readr-package.html"><a href="readr-package.html#总结-1"><i class="fa fa-check"></i><b>1.4.4</b> 总结</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="data-vroom.html"><a href="data-vroom.html"><i class="fa fa-check"></i><b>1.5</b> vroom</a>
<ul>
<li class="chapter" data-level="1.5.1" data-path="data-vroom.html"><a href="data-vroom.html#安装"><i class="fa fa-check"></i><b>1.5.1</b> 安装</a></li>
<li class="chapter" data-level="1.5.2" data-path="data-vroom.html"><a href="data-vroom.html#用法"><i class="fa fa-check"></i><b>1.5.2</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="1.6" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html"><i class="fa fa-check"></i><b>1.6</b> Rstudio导入</a>
<ul>
<li class="chapter" data-level="1.6.1" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html#rstudio-工具栏导入"><i class="fa fa-check"></i><b>1.6.1</b> rstudio 工具栏导入</a></li>
<li class="chapter" data-level="1.6.2" data-path="data-rstudio-addins.html"><a href="data-rstudio-addins.html#插件导入"><i class="fa fa-check"></i><b>1.6.2</b> 插件导入</a></li>
</ul></li>
<li class="chapter" data-level="1.7" data-path="data-file-path.html"><a href="data-file-path.html"><i class="fa fa-check"></i><b>1.7</b> 文件路径</a>
<ul>
<li class="chapter" data-level="1.7.1" data-path="data-file-path.html"><a href="data-file-path.html#指定路径"><i class="fa fa-check"></i><b>1.7.1</b> 指定路径</a></li>
<li class="chapter" data-level="1.7.2" data-path="data-file-path.html"><a href="data-file-path.html#默认路径"><i class="fa fa-check"></i><b>1.7.2</b> 默认路径</a></li>
</ul></li>
<li class="chapter" data-level="1.8" data-path="data-expand.html"><a href="data-expand.html"><i class="fa fa-check"></i><b>1.8</b> 拓展</a>
<ul>
<li class="chapter" data-level="1.8.1" data-path="data-expand.html"><a href="data-expand.html#tidyxl:package"><i class="fa fa-check"></i><b>1.8.1</b> tidyxl</a></li>
<li class="chapter" data-level="1.8.2" data-path="data-expand.html"><a href="data-expand.html#参考资料"><i class="fa fa-check"></i><b>1.8.2</b> 参考资料</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Data-Manipulation-dplyr.html"><a href="Data-Manipulation-dplyr.html"><i class="fa fa-check"></i><b>2</b> 数据处理之-dplyr</a>
<ul>
<li class="chapter" data-level="2.1" data-path="dplyr-description.html"><a href="dplyr-description.html"><i class="fa fa-check"></i><b>2.1</b> 前言</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="dplyr-description.html"><a href="dplyr-description.html#dplyr:install-package"><i class="fa fa-check"></i><b>2.1.1</b> 安装</a></li>
<li class="chapter" data-level="2.1.2" data-path="dplyr-description.html"><a href="dplyr-description.html#dplyr:difference-of-sql"><i class="fa fa-check"></i><b>2.1.2</b> Excel and Sql 类比</a></li>
<li class="chapter" data-level="2.1.3" data-path="dplyr-description.html"><a href="dplyr-description.html#常见问题"><i class="fa fa-check"></i><b>2.1.3</b> 常见问题</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="dplyr-usage.html"><a href="dplyr-usage.html"><i class="fa fa-check"></i><b>2.2</b> 基础用法</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-filter"><i class="fa fa-check"></i><b>2.2.1</b> filter</a></li>
<li class="chapter" data-level="2.2.2" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-select"><i class="fa fa-check"></i><b>2.2.2</b> select</a></li>
<li class="chapter" data-level="2.2.3" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-rename"><i class="fa fa-check"></i><b>2.2.3</b> rename</a></li>
<li class="chapter" data-level="2.2.4" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-relocate"><i class="fa fa-check"></i><b>2.2.4</b> relocate</a></li>
<li class="chapter" data-level="2.2.5" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-mutate"><i class="fa fa-check"></i><b>2.2.5</b> mutate</a></li>
<li class="chapter" data-level="2.2.6" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-arrange"><i class="fa fa-check"></i><b>2.2.6</b> arrange</a></li>
<li class="chapter" data-level="2.2.7" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-summarise"><i class="fa fa-check"></i><b>2.2.7</b> summarise</a></li>
<li class="chapter" data-level="2.2.8" data-path="dplyr-usage.html"><a href="dplyr-usage.html#dplyr-groupby"><i class="fa fa-check"></i><b>2.2.8</b> group_by</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="dplyr-functions.html"><a href="dplyr-functions.html"><i class="fa fa-check"></i><b>2.3</b> 常用函数</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="dplyr-functions.html"><a href="dplyr-functions.html#条件判断"><i class="fa fa-check"></i><b>2.3.1</b> 条件判断</a></li>
<li class="chapter" data-level="2.3.2" data-path="dplyr-functions.html"><a href="dplyr-functions.html#case_when"><i class="fa fa-check"></i><b>2.3.2</b> case_when</a></li>
<li class="chapter" data-level="2.3.3" data-path="dplyr-functions.html"><a href="dplyr-functions.html#计数函数"><i class="fa fa-check"></i><b>2.3.3</b> 计数函数</a></li>
<li class="chapter" data-level="2.3.4" data-path="dplyr-functions.html"><a href="dplyr-functions.html#排序函数"><i class="fa fa-check"></i><b>2.3.4</b> 排序函数</a></li>
<li class="chapter" data-level="2.3.5" data-path="dplyr-functions.html"><a href="dplyr-functions.html#提取向量"><i class="fa fa-check"></i><b>2.3.5</b> 提取向量</a></li>
<li class="chapter" data-level="2.3.6" data-path="dplyr-functions.html"><a href="dplyr-functions.html#dplyr:slice"><i class="fa fa-check"></i><b>2.3.6</b> slice 系列</a></li>
<li class="chapter" data-level="2.3.7" data-path="dplyr-functions.html"><a href="dplyr-functions.html#group-系列"><i class="fa fa-check"></i><b>2.3.7</b> group 系列</a></li>
<li class="chapter" data-level="2.3.8" data-path="dplyr-functions.html"><a href="dplyr-functions.html#其它函数"><i class="fa fa-check"></i><b>2.3.8</b> 其它函数</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html"><i class="fa fa-check"></i><b>2.4</b> 表关联</a>
<ul>
<li class="chapter" data-level="2.4.1" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html#dplyr:merge-table-usage"><i class="fa fa-check"></i><b>2.4.1</b> 两表关联</a></li>
<li class="chapter" data-level="2.4.2" data-path="dplyr-merge-two-table.html"><a href="dplyr-merge-two-table.html#dplyr:merge-multiple-table"><i class="fa fa-check"></i><b>2.4.2</b> 多表操作</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html"><i class="fa fa-check"></i><b>2.5</b> 分组操作</a>
<ul>
<li class="chapter" data-level="2.5.1" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#添加分组"><i class="fa fa-check"></i><b>2.5.1</b> 添加分组</a></li>
<li class="chapter" data-level="2.5.2" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#查看分组"><i class="fa fa-check"></i><b>2.5.2</b> 查看分组</a></li>
<li class="chapter" data-level="2.5.3" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#更改和添加分组变量"><i class="fa fa-check"></i><b>2.5.3</b> 更改和添加分组变量</a></li>
<li class="chapter" data-level="2.5.4" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#删除分组变量"><i class="fa fa-check"></i><b>2.5.4</b> 删除分组变量</a></li>
<li class="chapter" data-level="2.5.5" data-path="dplyr-groupby-manipulation.html"><a href="dplyr-groupby-manipulation.html#动词影响"><i class="fa fa-check"></i><b>2.5.5</b> 动词影响</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html"><i class="fa fa-check"></i><b>2.6</b> 列操作</a>
<ul>
<li class="chapter" data-level="2.6.1" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#dplyr-column-manipulation-basic-usage"><i class="fa fa-check"></i><b>2.6.1</b> 基础用法</a></li>
<li class="chapter" data-level="2.6.2" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#多种函数功能"><i class="fa fa-check"></i><b>2.6.2</b> 多种函数功能</a></li>
<li class="chapter" data-level="2.6.3" data-path="dplyr-column-manipulation.html"><a href="dplyr-column-manipulation.html#当前列"><i class="fa fa-check"></i><b>2.6.3</b> 当前列</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html"><i class="fa fa-check"></i><b>2.7</b> 行操作</a>
<ul>
<li class="chapter" data-level="2.7.1" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html#比较差异"><i class="fa fa-check"></i><b>2.7.1</b> 比较差异</a></li>
<li class="chapter" data-level="2.7.2" data-path="dplyr-row-manipulation.html"><a href="dplyr-row-manipulation.html#常用案例"><i class="fa fa-check"></i><b>2.7.2</b> 常用案例</a></li>
</ul></li>
<li class="chapter" data-level="2.8" data-path="dplyr-programming.html"><a href="dplyr-programming.html"><i class="fa fa-check"></i><b>2.8</b> <code>dplyr</code>编程</a>
<ul>
<li class="chapter" data-level="2.8.1" data-path="dplyr-programming.html"><a href="dplyr-programming.html#案例"><i class="fa fa-check"></i><b>2.8.1</b> 案例</a></li>
</ul></li>
<li class="chapter" data-level="2.9" data-path="dplyr-reference-material.html"><a href="dplyr-reference-material.html"><i class="fa fa-check"></i><b>2.9</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Data-tidyr-package.html"><a href="Data-tidyr-package.html"><i class="fa fa-check"></i><b>3</b> 整洁数据之 tidyr</a>
<ul>
<li class="chapter" data-level="3.1" data-path="tidyr-useage.html"><a href="tidyr-useage.html"><i class="fa fa-check"></i><b>3.1</b> tidyr 介绍</a>
<ul>
<li class="chapter" data-level="3.1.1" data-path="tidyr-useage.html"><a href="tidyr-useage.html#tidyr:install"><i class="fa fa-check"></i><b>3.1.1</b> 安装</a></li>
<li class="chapter" data-level="3.1.2" data-path="tidyr-useage.html"><a href="tidyr-useage.html#tidyr:functions"><i class="fa fa-check"></i><b>3.1.2</b> 主要功能</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="pivoting.html"><a href="pivoting.html"><i class="fa fa-check"></i><b>3.2</b> 长宽转换</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="pivoting.html"><a href="pivoting.html#宽转长"><i class="fa fa-check"></i><b>3.2.1</b> 宽转长</a></li>
<li class="chapter" data-level="3.2.2" data-path="pivoting.html"><a href="pivoting.html#用法-1"><i class="fa fa-check"></i><b>3.2.2</b> 用法</a></li>
<li class="chapter" data-level="3.2.3" data-path="pivoting.html"><a href="pivoting.html#长转宽"><i class="fa fa-check"></i><b>3.2.3</b> 长转宽</a></li>
<li class="chapter" data-level="3.2.4" data-path="pivoting.html"><a href="pivoting.html#用法-2"><i class="fa fa-check"></i><b>3.2.4</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="tidyr-rectangle.html"><a href="tidyr-rectangle.html"><i class="fa fa-check"></i><b>3.3</b> 矩形数据</a></li>
<li class="chapter" data-level="3.4" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html"><i class="fa fa-check"></i><b>3.4</b> 嵌套数据</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html#基础"><i class="fa fa-check"></i><b>3.4.1</b> 基础</a></li>
<li class="chapter" data-level="3.4.2" data-path="tidyr-nest-data.html"><a href="tidyr-nest-data.html#嵌套数据和模型"><i class="fa fa-check"></i><b>3.4.2</b> 嵌套数据和模型</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="character-vector.html"><a href="character-vector.html"><i class="fa fa-check"></i><b>3.5</b> 字符处理</a>
<ul>
<li class="chapter" data-level="3.5.1" data-path="character-vector.html"><a href="character-vector.html#新列提取"><i class="fa fa-check"></i><b>3.5.1</b> 新列提取</a></li>
<li class="chapter" data-level="3.5.2" data-path="character-vector.html"><a href="character-vector.html#拆分"><i class="fa fa-check"></i><b>3.5.2</b> 拆分</a></li>
<li class="chapter" data-level="3.5.3" data-path="character-vector.html"><a href="character-vector.html#列拆分行"><i class="fa fa-check"></i><b>3.5.3</b> 列拆分行</a></li>
<li class="chapter" data-level="3.5.4" data-path="character-vector.html"><a href="character-vector.html#合并多列"><i class="fa fa-check"></i><b>3.5.4</b> 合并多列</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="tidyr-expand.html"><a href="tidyr-expand.html"><i class="fa fa-check"></i><b>3.6</b> 扩展数据框</a></li>
<li class="chapter" data-level="3.7" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html"><i class="fa fa-check"></i><b>3.7</b> 缺失值</a>
<ul>
<li class="chapter" data-level="3.7.1" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#replace_na"><i class="fa fa-check"></i><b>3.7.1</b> replace_na</a></li>
<li class="chapter" data-level="3.7.2" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#fill"><i class="fa fa-check"></i><b>3.7.2</b> fill</a></li>
<li class="chapter" data-level="3.7.3" data-path="tidyr-fill-NA.html"><a href="tidyr-fill-NA.html#drop_na"><i class="fa fa-check"></i><b>3.7.3</b> drop_na</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="character-handling.html"><a href="character-handling.html"><i class="fa fa-check"></i><b>4</b> 字符处理</a>
<ul>
<li class="chapter" data-level="4.1" data-path="character-base-R.html"><a href="character-base-R.html"><i class="fa fa-check"></i><b>4.1</b> base R</a>
<ul>
<li class="chapter" data-level="4.1.1" data-path="character-base-R.html"><a href="character-base-R.html#单双引号"><i class="fa fa-check"></i><b>4.1.1</b> 单双引号</a></li>
<li class="chapter" data-level="4.1.2" data-path="character-base-R.html"><a href="character-base-R.html#转义"><i class="fa fa-check"></i><b>4.1.2</b> 转义</a></li>
<li class="chapter" data-level="4.1.3" data-path="character-base-R.html"><a href="character-base-R.html#常用函数"><i class="fa fa-check"></i><b>4.1.3</b> 常用函数</a></li>
<li class="chapter" data-level="4.1.4" data-path="character-base-R.html"><a href="character-base-R.html#newfeatures"><i class="fa fa-check"></i><b>4.1.4</b> 新特性</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html"><i class="fa fa-check"></i><b>4.2</b> stringr</a>
<ul>
<li class="chapter" data-level="4.2.1" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-install"><i class="fa fa-check"></i><b>4.2.1</b> 安装</a></li>
<li class="chapter" data-level="4.2.2" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-usage"><i class="fa fa-check"></i><b>4.2.2</b> 基本使用</a></li>
<li class="chapter" data-level="4.2.3" data-path="character-stringr-packages.html"><a href="character-stringr-packages.html#stringr-functions"><i class="fa fa-check"></i><b>4.2.3</b> 常用函数</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="character-application.html"><a href="character-application.html"><i class="fa fa-check"></i><b>4.3</b> 综合运用</a>
<ul>
<li class="chapter" data-level="4.3.1" data-path="character-application.html"><a href="character-application.html#实现excel函数"><i class="fa fa-check"></i><b>4.3.1</b> 实现excel函数</a></li>
<li class="chapter" data-level="4.3.2" data-path="character-application.html"><a href="character-application.html#使用案例"><i class="fa fa-check"></i><b>4.3.2</b> 使用案例</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="character-the-difference-stringr-and-base.html"><a href="character-the-difference-stringr-and-base.html"><i class="fa fa-check"></i><b>4.4</b> base 和 stringr</a></li>
<li class="chapter" data-level="4.5" data-path="character-reference-material.html"><a href="character-reference-material.html"><i class="fa fa-check"></i><b>4.5</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="datetime.html"><a href="datetime.html"><i class="fa fa-check"></i><b>5</b> 时间处理</a>
<ul>
<li class="chapter" data-level="5.1" data-path="datetime-base-R.html"><a href="datetime-base-R.html"><i class="fa fa-check"></i><b>5.1</b> base R</a>
<ul>
<li class="chapter" data-level="5.1.1" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-date-class"><i class="fa fa-check"></i><b>5.1.1</b> Date</a></li>
<li class="chapter" data-level="5.1.2" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-POSIXct-class"><i class="fa fa-check"></i><b>5.1.2</b> POSIXct</a></li>
<li class="chapter" data-level="5.1.3" data-path="datetime-base-R.html"><a href="datetime-base-R.html#the-POSIXlt-class"><i class="fa fa-check"></i><b>5.1.3</b> POSIXlt</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="lubridate.html"><a href="lubridate.html"><i class="fa fa-check"></i><b>5.2</b> lubridate</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="lubridate.html"><a href="lubridate.html#lubridate-install"><i class="fa fa-check"></i><b>5.2.1</b> 安装包</a></li>
<li class="chapter" data-level="5.2.2" data-path="lubridate.html"><a href="lubridate.html#get-current-datetime"><i class="fa fa-check"></i><b>5.2.2</b> 当前时间日期</a></li>
<li class="chapter" data-level="5.2.3" data-path="lubridate.html"><a href="lubridate.html#make-datetime"><i class="fa fa-check"></i><b>5.2.3</b> 构造日期时间</a></li>
<li class="chapter" data-level="5.2.4" data-path="lubridate.html"><a href="lubridate.html#parse-datetime"><i class="fa fa-check"></i><b>5.2.4</b> 解析日期时间</a></li>
<li class="chapter" data-level="5.2.5" data-path="lubridate.html"><a href="lubridate.html#extracting-datetime-information"><i class="fa fa-check"></i><b>5.2.5</b> 提取日期时间成分</a></li>
<li class="chapter" data-level="5.2.6" data-path="lubridate.html"><a href="lubridate.html#time-zones"><i class="fa fa-check"></i><b>5.2.6</b> 处理时区</a></li>
<li class="chapter" data-level="5.2.7" data-path="lubridate.html"><a href="lubridate.html#interveal"><i class="fa fa-check"></i><b>5.2.7</b> 时间间隔</a></li>
<li class="chapter" data-level="5.2.8" data-path="lubridate.html"><a href="lubridate.html#calculate-datetime"><i class="fa fa-check"></i><b>5.2.8</b> 时间日期计算</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="datetime-application.html"><a href="datetime-application.html"><i class="fa fa-check"></i><b>5.3</b> 综合运用</a>
<ul>
<li class="chapter" data-level="5.3.1" data-path="datetime-application.html"><a href="datetime-application.html#日报同环比计算"><i class="fa fa-check"></i><b>5.3.1</b> 日报同环比计算</a></li>
<li class="chapter" data-level="5.3.2" data-path="datetime-application.html"><a href="datetime-application.html#清洗不同类型日期格式"><i class="fa fa-check"></i><b>5.3.2</b> 清洗不同类型日期格式</a></li>
<li class="chapter" data-level="5.3.3" data-path="datetime-application.html"><a href="datetime-application.html#扫码后中奖时间匹配"><i class="fa fa-check"></i><b>5.3.3</b> 扫码后中奖时间匹配</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html"><i class="fa fa-check"></i><b>5.4</b> 补充资料</a>
<ul>
<li class="chapter" data-level="5.4.1" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html#excel-and-r"><i class="fa fa-check"></i><b>5.4.1</b> Excel and R</a></li>
<li class="chapter" data-level="5.4.2" data-path="datetime-additional-information.html"><a href="datetime-additional-information.html#参考资料-1"><i class="fa fa-check"></i><b>5.4.2</b> 参考资料</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="forcats.html"><a href="forcats.html"><i class="fa fa-check"></i><b>6</b> 因子介绍</a>
<ul>
<li class="chapter" data-level="6.1" data-path="forcats-introduction.html"><a href="forcats-introduction.html"><i class="fa fa-check"></i><b>6.1</b> 介绍</a>
<ul>
<li class="chapter" data-level="6.1.1" data-path="forcats-introduction.html"><a href="forcats-introduction.html#forcats:install"><i class="fa fa-check"></i><b>6.1.1</b> 安装</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="forcats-usage.html"><a href="forcats-usage.html"><i class="fa fa-check"></i><b>6.2</b> 用法</a>
<ul>
<li class="chapter" data-level="6.2.1" data-path="forcats-usage.html"><a href="forcats-usage.html#创建因子"><i class="fa fa-check"></i><b>6.2.1</b> 创建因子</a></li>
<li class="chapter" data-level="6.2.2" data-path="forcats-usage.html"><a href="forcats-usage.html#修改因子顺序"><i class="fa fa-check"></i><b>6.2.2</b> 修改因子顺序</a></li>
<li class="chapter" data-level="6.2.3" data-path="forcats-usage.html"><a href="forcats-usage.html#修改因子级别"><i class="fa fa-check"></i><b>6.2.3</b> 修改因子级别</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Data-Manipulation-datatable.html"><a href="Data-Manipulation-datatable.html"><i class="fa fa-check"></i><b>7</b> data.table</a>
<ul>
<li class="chapter" data-level="7.1" data-path="datatable-description.html"><a href="datatable-description.html"><i class="fa fa-check"></i><b>7.1</b> 基础介绍</a>
<ul>
<li class="chapter" data-level="7.1.1" data-path="datatable-description.html"><a href="datatable-description.html#读取数据"><i class="fa fa-check"></i><b>7.1.1</b> 读取数据</a></li>
<li class="chapter" data-level="7.1.2" data-path="datatable-description.html"><a href="datatable-description.html#基本格式"><i class="fa fa-check"></i><b>7.1.2</b> 基本格式</a></li>
<li class="chapter" data-level="7.1.3" data-path="datatable-description.html"><a href="datatable-description.html#i-j-by-使用"><i class="fa fa-check"></i><b>7.1.3</b> i j by 使用</a></li>
<li class="chapter" data-level="7.1.4" data-path="datatable-description.html"><a href="datatable-description.html#行列筛选总结"><i class="fa fa-check"></i><b>7.1.4</b> 行列筛选总结</a></li>
</ul></li>
<li class="chapter" data-level="7.2" data-path="datatable-usage.html"><a href="datatable-usage.html"><i class="fa fa-check"></i><b>7.2</b> 常规操作</a>
<ul>
<li class="chapter" data-level="7.2.1" data-path="datatable-usage.html"><a href="datatable-usage.html#行筛选"><i class="fa fa-check"></i><b>7.2.1</b> 行筛选</a></li>
<li class="chapter" data-level="7.2.2" data-path="datatable-usage.html"><a href="datatable-usage.html#新增更新列"><i class="fa fa-check"></i><b>7.2.2</b> 新增更新列</a></li>
<li class="chapter" data-level="7.2.3" data-path="datatable-usage.html"><a href="datatable-usage.html#排序"><i class="fa fa-check"></i><b>7.2.3</b> 排序</a></li>
</ul></li>
<li class="chapter" data-level="7.3" data-path="datatable-function.html"><a href="datatable-function.html"><i class="fa fa-check"></i><b>7.3</b> 常用函数</a>
<ul>
<li class="chapter" data-level="7.3.1" data-path="datatable-function.html"><a href="datatable-function.html#特殊符号"><i class="fa fa-check"></i><b>7.3.1</b> 特殊符号</a></li>
<li class="chapter" data-level="7.3.2" data-path="datatable-function.html"><a href="datatable-function.html#排序函数-1"><i class="fa fa-check"></i><b>7.3.2</b> 排序函数</a></li>
<li class="chapter" data-level="7.3.3" data-path="datatable-function.html"><a href="datatable-function.html#非重复计数"><i class="fa fa-check"></i><b>7.3.3</b> 非重复计数</a></li>
<li class="chapter" data-level="7.3.4" data-path="datatable-function.html"><a href="datatable-function.html#判断函数"><i class="fa fa-check"></i><b>7.3.4</b> 判断函数</a></li>
<li class="chapter" data-level="7.3.5" data-path="datatable-function.html"><a href="datatable-function.html#交集-差集-合并"><i class="fa fa-check"></i><b>7.3.5</b> 交集 差集 合并</a></li>
<li class="chapter" data-level="7.3.6" data-path="datatable-function.html"><a href="datatable-function.html#长宽转换"><i class="fa fa-check"></i><b>7.3.6</b> 长宽转换</a></li>
<li class="chapter" data-level="7.3.7" data-path="datatable-function.html"><a href="datatable-function.html#表连接"><i class="fa fa-check"></i><b>7.3.7</b> 表连接</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html"><i class="fa fa-check"></i><b>7.4</b> 高级函数</a>
<ul>
<li class="chapter" data-level="7.4.1" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#groupingsets"><i class="fa fa-check"></i><b>7.4.1</b> groupingsets</a></li>
<li class="chapter" data-level="7.4.2" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#rleid"><i class="fa fa-check"></i><b>7.4.2</b> rleid</a></li>
<li class="chapter" data-level="7.4.3" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#shift"><i class="fa fa-check"></i><b>7.4.3</b> shift</a></li>
<li class="chapter" data-level="7.4.4" data-path="datatable-advanced-functions.html"><a href="datatable-advanced-functions.html#j"><i class="fa fa-check"></i><b>7.4.4</b> J</a></li>
</ul></li>
<li class="chapter" data-level="7.5" data-path="datatable-tips.html"><a href="datatable-tips.html"><i class="fa fa-check"></i><b>7.5</b> 小技巧</a>
<ul>
<li class="chapter" data-level="7.5.1" data-path="datatable-tips.html"><a href="datatable-tips.html#用抑制中间过程输出"><i class="fa fa-check"></i><b>7.5.1</b> 用{}抑制中间过程输出</a></li>
<li class="chapter" data-level="7.5.2" data-path="datatable-tips.html"><a href="datatable-tips.html#使用打印data.table"><i class="fa fa-check"></i><b>7.5.2</b> 使用[]打印data.table</a></li>
</ul></li>
<li class="chapter" data-level="7.6" data-path="datatable-application.html"><a href="datatable-application.html"><i class="fa fa-check"></i><b>7.6</b> 运用</a>
<ul>
<li class="chapter" data-level="7.6.1" data-path="datatable-application.html"><a href="datatable-application.html#自定义函数计算"><i class="fa fa-check"></i><b>7.6.1</b> 自定义函数计算</a></li>
<li class="chapter" data-level="7.6.2" data-path="datatable-application.html"><a href="datatable-application.html#带汇总的聚合运算"><i class="fa fa-check"></i><b>7.6.2</b> 带汇总的聚合运算</a></li>
<li class="chapter" data-level="7.6.3" data-path="datatable-application.html"><a href="datatable-application.html#行列转变"><i class="fa fa-check"></i><b>7.6.3</b> 行列转变</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="8" data-path="database.html"><a href="database.html"><i class="fa fa-check"></i><b>8</b> database</a>
<ul>
<li class="chapter" data-level="8.1" data-path="database-install.html"><a href="database-install.html"><i class="fa fa-check"></i><b>8.1</b> 安装数据库</a></li>
<li class="chapter" data-level="8.2" data-path="database-odbc-package.html"><a href="database-odbc-package.html"><i class="fa fa-check"></i><b>8.2</b> odbc包</a>
<ul>
<li class="chapter" data-level="8.2.1" data-path="database-odbc-package.html"><a href="database-odbc-package.html#安装包"><i class="fa fa-check"></i><b>8.2.1</b> 安装包</a></li>
<li class="chapter" data-level="8.2.2" data-path="database-odbc-package.html"><a href="database-odbc-package.html#驱动安装"><i class="fa fa-check"></i><b>8.2.2</b> 驱动安装</a></li>
<li class="chapter" data-level="8.2.3" data-path="database-odbc-package.html"><a href="database-odbc-package.html#连接数据库"><i class="fa fa-check"></i><b>8.2.3</b> 连接数据库</a></li>
<li class="chapter" data-level="8.2.4" data-path="database-odbc-package.html"><a href="database-odbc-package.html#读写数据库"><i class="fa fa-check"></i><b>8.2.4</b> 读写数据库</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="database-DBI-package.html"><a href="database-DBI-package.html"><i class="fa fa-check"></i><b>8.3</b> DBI包</a>
<ul>
<li class="chapter" data-level="8.3.1" data-path="database-DBI-package.html"><a href="database-DBI-package.html#安装-1"><i class="fa fa-check"></i><b>8.3.1</b> 安装</a></li>
<li class="chapter" data-level="8.3.2" data-path="database-DBI-package.html"><a href="database-DBI-package.html#连接数据库-1"><i class="fa fa-check"></i><b>8.3.2</b> 连接数据库</a></li>
<li class="chapter" data-level="8.3.3" data-path="database-DBI-package.html"><a href="database-DBI-package.html#读写数据库-1"><i class="fa fa-check"></i><b>8.3.3</b> 读写数据库</a></li>
<li class="chapter" data-level="8.3.4" data-path="database-DBI-package.html"><a href="database-DBI-package.html#其它函数介绍"><i class="fa fa-check"></i><b>8.3.4</b> 其它函数介绍</a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="database-else-package.html"><a href="database-else-package.html"><i class="fa fa-check"></i><b>8.4</b> 其他R包</a>
<ul>
<li class="chapter" data-level="8.4.1" data-path="database-else-package.html"><a href="database-else-package.html#rodbc包"><i class="fa fa-check"></i><b>8.4.1</b> RODBC包</a></li>
<li class="chapter" data-level="8.4.2" data-path="database-else-package.html"><a href="database-else-package.html#roracle包"><i class="fa fa-check"></i><b>8.4.2</b> ROracle包</a></li>
<li class="chapter" data-level="8.4.3" data-path="database-else-package.html"><a href="database-else-package.html#rmysql包"><i class="fa fa-check"></i><b>8.4.3</b> RMySQL包</a></li>
<li class="chapter" data-level="8.4.4" data-path="database-else-package.html"><a href="database-else-package.html#rsqlite"><i class="fa fa-check"></i><b>8.4.4</b> RSQLite</a></li>
</ul></li>
<li class="chapter" data-level="8.5" data-path="database-big-data.html"><a href="database-big-data.html"><i class="fa fa-check"></i><b>8.5</b> 大数据相关R包</a>
<ul>
<li class="chapter" data-level="8.5.1" data-path="database-big-data.html"><a href="database-big-data.html#sparklyr"><i class="fa fa-check"></i><b>8.5.1</b> sparklyr</a></li>
<li class="chapter" data-level="8.5.2" data-path="database-big-data.html"><a href="database-big-data.html#RClickhouse"><i class="fa fa-check"></i><b>8.5.2</b> RClickhouse</a></li>
</ul></li>
<li class="chapter" data-level="8.6" data-path="database-FAQ.html"><a href="database-FAQ.html"><i class="fa fa-check"></i><b>8.6</b> 常见问题</a>
<ul>
<li class="chapter" data-level="8.6.1" data-path="database-FAQ.html"><a href="database-FAQ.html#乱码问题"><i class="fa fa-check"></i><b>8.6.1</b> 乱码问题</a></li>
<li class="chapter" data-level="8.6.2" data-path="database-FAQ.html"><a href="database-FAQ.html#无法连接问题"><i class="fa fa-check"></i><b>8.6.2</b> 无法连接问题</a></li>
<li class="chapter" data-level="8.6.3" data-path="database-FAQ.html"><a href="database-FAQ.html#远程连接"><i class="fa fa-check"></i><b>8.6.3</b> 远程连接</a></li>
<li class="chapter" data-level="8.6.4" data-path="database-FAQ.html"><a href="database-FAQ.html#跳板机连接"><i class="fa fa-check"></i><b>8.6.4</b> 跳板机连接</a></li>
</ul></li>
<li class="chapter" data-level="8.7" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html"><i class="fa fa-check"></i><b>8.7</b> dbplyr</a>
<ul>
<li class="chapter" data-level="8.7.1" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#安装-2"><i class="fa fa-check"></i><b>8.7.1</b> 安装</a></li>
<li class="chapter" data-level="8.7.2" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#基础用法-1"><i class="fa fa-check"></i><b>8.7.2</b> 基础用法</a></li>
<li class="chapter" data-level="8.7.3" data-path="database-dbplyr-package.html"><a href="database-dbplyr-package.html#无法正确转化"><i class="fa fa-check"></i><b>8.7.3</b> 无法正确转化</a></li>
</ul></li>
<li class="chapter" data-level="8.8" data-path="database-reference-material.html"><a href="database-reference-material.html"><i class="fa fa-check"></i><b>8.8</b> 参考资料</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="R-loop-structure.html"><a href="R-loop-structure.html"><i class="fa fa-check"></i><b>9</b> 循环结构</a>
<ul>
<li class="chapter" data-level="9.1" data-path="R-loop-description.html"><a href="R-loop-description.html"><i class="fa fa-check"></i><b>9.1</b> R循环介绍</a>
<ul>
<li class="chapter" data-level="9.1.1" data-path="R-loop-description.html"><a href="R-loop-description.html#R:loop-example"><i class="fa fa-check"></i><b>9.1.1</b> 简单示例</a></li>
<li class="chapter" data-level="9.1.2" data-path="R-loop-description.html"><a href="R-loop-description.html#three:loop-structure"><i class="fa fa-check"></i><b>9.1.2</b> 循环结构</a></li>
<li class="chapter" data-level="9.1.3" data-path="R-loop-description.html"><a href="R-loop-description.html#loop:control"><i class="fa fa-check"></i><b>9.1.3</b> 循环控制</a></li>
<li class="chapter" data-level="9.1.4" data-path="R-loop-description.html"><a href="R-loop-description.html#嵌套循环"><i class="fa fa-check"></i><b>9.1.4</b> 嵌套循环</a></li>
</ul></li>
<li class="chapter" data-level="9.2" data-path="loop-changes.html"><a href="loop-changes.html"><i class="fa fa-check"></i><b>9.2</b> 循环变化</a>
<ul>
<li class="chapter" data-level="9.2.1" data-path="loop-changes.html"><a href="loop-changes.html#修改已有对象"><i class="fa fa-check"></i><b>9.2.1</b> 修改已有对象</a></li>
<li class="chapter" data-level="9.2.2" data-path="loop-changes.html"><a href="loop-changes.html#循环模式"><i class="fa fa-check"></i><b>9.2.2</b> 循环模式</a></li>
<li class="chapter" data-level="9.2.3" data-path="loop-changes.html"><a href="loop-changes.html#未知长度输出"><i class="fa fa-check"></i><b>9.2.3</b> 未知长度输出</a></li>
</ul></li>
<li class="chapter" data-level="9.3" data-path="apply-function.html"><a href="apply-function.html"><i class="fa fa-check"></i><b>9.3</b> apply系列函数</a>
<ul>
<li class="chapter" data-level="9.3.1" data-path="apply-function.html"><a href="apply-function.html#lapply"><i class="fa fa-check"></i><b>9.3.1</b> lapply 循环迭代</a></li>
<li class="chapter" data-level="9.3.2" data-path="apply-function.html"><a href="apply-function.html#sapply"><i class="fa fa-check"></i><b>9.3.2</b> sapply</a></li>
<li class="chapter" data-level="9.3.3" data-path="apply-function.html"><a href="apply-function.html#vapply"><i class="fa fa-check"></i><b>9.3.3</b> vapply 迭代安全函数</a></li>
<li class="chapter" data-level="9.3.4" data-path="apply-function.html"><a href="apply-function.html#apply"><i class="fa fa-check"></i><b>9.3.4</b> apply 多维数据</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="10" data-path="purrr-Iteration.html"><a href="purrr-Iteration.html"><i class="fa fa-check"></i><b>10</b> 循环迭代purrr介绍</a>
<ul>
<li class="chapter" data-level="10.1" data-path="安装-3.html"><a href="安装-3.html"><i class="fa fa-check"></i><b>10.1</b> 安装</a></li>
<li class="chapter" data-level="10.2" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html"><i class="fa fa-check"></i><b>10.2</b> 常规用法</a>
<ul>
<li class="chapter" data-level="10.2.1" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html#map-系列"><i class="fa fa-check"></i><b>10.2.1</b> map 系列</a></li>
<li class="chapter" data-level="10.2.2" data-path="purrr-basic-usage.html"><a href="purrr-basic-usage.html#pmap-系列"><i class="fa fa-check"></i><b>10.2.2</b> pmap 系列</a></li>
</ul></li>
<li class="chapter" data-level="10.3" data-path="purrr-map.html"><a href="purrr-map.html"><i class="fa fa-check"></i><b>10.3</b> map系列函数</a>
<ul>
<li class="chapter" data-level="10.3.1" data-path="purrr-map.html"><a href="purrr-map.html#用法-3"><i class="fa fa-check"></i><b>10.3.1</b> 用法</a></li>
<li class="chapter" data-level="10.3.2" data-path="purrr-map.html"><a href="purrr-map.html#案例-5"><i class="fa fa-check"></i><b>10.3.2</b> 案例</a></li>
</ul></li>
<li class="chapter" data-level="10.4" data-path="purrr-map2.html"><a href="purrr-map2.html"><i class="fa fa-check"></i><b>10.4</b> map2 系列函数</a></li>
<li class="chapter" data-level="10.5" data-path="purrr-multi-parameter.html"><a href="purrr-multi-parameter.html"><i class="fa fa-check"></i><b>10.5</b> pmap系列函数</a></li>
<li class="chapter" data-level="10.6" data-path="purrr-reduce.html"><a href="purrr-reduce.html"><i class="fa fa-check"></i><b>10.6</b> 归约累计函数</a>
<ul>
<li class="chapter" data-level="10.6.1" data-path="purrr-reduce.html"><a href="purrr-reduce.html#reduce-函数"><i class="fa fa-check"></i><b>10.6.1</b> reduce 函数</a></li>
<li class="chapter" data-level="10.6.2" data-path="purrr-reduce.html"><a href="purrr-reduce.html#accumulate-函数"><i class="fa fa-check"></i><b>10.6.2</b> accumulate 函数</a></li>
</ul></li>
<li class="chapter" data-level="10.7" data-path="purrr-safely-functions.html"><a href="purrr-safely-functions.html"><i class="fa fa-check"></i><b>10.7</b> 安全函数</a></li>
<li class="chapter" data-level="10.8" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html"><i class="fa fa-check"></i><b>10.8</b> 其他函数介绍</a>
<ul>
<li class="chapter" data-level="10.8.1" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#flatten-系列"><i class="fa fa-check"></i><b>10.8.1</b> flatten 系列</a></li>
<li class="chapter" data-level="10.8.2" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#imap-函数"><i class="fa fa-check"></i><b>10.8.2</b> imap 函数</a></li>
<li class="chapter" data-level="10.8.3" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#walk-系列"><i class="fa fa-check"></i><b>10.8.3</b> walk 系列</a></li>
<li class="chapter" data-level="10.8.4" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#逻辑判断函数"><i class="fa fa-check"></i><b>10.8.4</b> 逻辑判断函数</a></li>
<li class="chapter" data-level="10.8.5" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#提取函数"><i class="fa fa-check"></i><b>10.8.5</b> 提取函数</a></li>
<li class="chapter" data-level="10.8.6" data-path="purrr-else-functions.html"><a href="purrr-else-functions.html#筛选函数"><i class="fa fa-check"></i><b>10.8.6</b> 筛选函数</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="11" data-path="self-define-function.html"><a href="self-define-function.html"><i class="fa fa-check"></i><b>11</b> 自定义函数</a>
<ul>
<li class="chapter" data-level="11.1" data-path="define-function-example.html"><a href="define-function-example.html"><i class="fa fa-check"></i><b>11.1</b> 简单示例</a></li>
<li class="chapter" data-level="11.2" data-path="define-function-conditional-execution.html"><a href="define-function-conditional-execution.html"><i class="fa fa-check"></i><b>11.2</b> 条件执行</a>
<ul>
<li class="chapter" data-level="11.2.1" data-path="define-function-conditional-execution.html"><a href="define-function-conditional-execution.html#多条件执行"><i class="fa fa-check"></i><b>11.2.1</b> 多条件执行</a></li>
</ul></li>
<li class="chapter" data-level="11.3" data-path="define-function-parameter.html"><a href="define-function-parameter.html"><i class="fa fa-check"></i><b>11.3</b> 函数参数</a>
<ul>
<li class="chapter" data-level="11.3.1" data-path="define-function-parameter.html"><a href="define-function-parameter.html#参数名称"><i class="fa fa-check"></i><b>11.3.1</b> 参数名称</a></li>
<li class="chapter" data-level="11.3.2" data-path="define-function-parameter.html"><a href="define-function-parameter.html#检查参数值"><i class="fa fa-check"></i><b>11.3.2</b> 检查参数值</a></li>
<li class="chapter" data-level="11.3.3" data-path="define-function-parameter.html"><a href="define-function-parameter.html#参数-5"><i class="fa fa-check"></i><b>11.3.3</b> …参数</a></li>
</ul></li>
<li class="chapter" data-level="11.4" data-path="function-return.html"><a href="function-return.html"><i class="fa fa-check"></i><b>11.4</b> 返回值</a>
<ul>
<li class="chapter" data-level="11.4.1" data-path="function-return.html"><a href="function-return.html#显式返回"><i class="fa fa-check"></i><b>11.4.1</b> 显式返回</a></li>
<li class="chapter" data-level="11.4.2" data-path="function-return.html"><a href="function-return.html#编写管道函数"><i class="fa fa-check"></i><b>11.4.2</b> 编写管道函数</a></li>
</ul></li>
<li class="chapter" data-level="11.5" data-path="function-environment.html"><a href="function-environment.html"><i class="fa fa-check"></i><b>11.5</b> 环境</a></li>
<li class="chapter" data-level="11.6" data-path="function-expand.html"><a href="function-expand.html"><i class="fa fa-check"></i><b>11.6</b> 拓展部分</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="file-system-operation.html"><a href="file-system-operation.html"><i class="fa fa-check"></i><b>12</b> R语言文件系统操作</a>
<ul>
<li class="chapter" data-level="12.1" data-path="file-base-r.html"><a href="file-base-r.html"><i class="fa fa-check"></i><b>12.1</b> base R</a>
<ul>
<li class="chapter" data-level="12.1.1" data-path="file-base-r.html"><a href="file-base-r.html#base:r-usage"><i class="fa fa-check"></i><b>12.1.1</b> 用法</a></li>
</ul></li>
<li class="chapter" data-level="12.2" data-path="fs-package.html"><a href="fs-package.html"><i class="fa fa-check"></i><b>12.2</b> fs package</a>
<ul>
<li class="chapter" data-level="12.2.1" data-path="fs-package.html"><a href="fs-package.html#fs-install"><i class="fa fa-check"></i><b>12.2.1</b> 安装</a></li>
<li class="chapter" data-level="12.2.2" data-path="fs-package.html"><a href="fs-package.html#fs-advanced"><i class="fa fa-check"></i><b>12.2.2</b> 优势</a></li>
<li class="chapter" data-level="12.2.3" data-path="fs-package.html"><a href="fs-package.html#fs-usage"><i class="fa fa-check"></i><b>12.2.3</b> 基础用法</a></li>
</ul></li>
<li class="chapter" data-level="12.3" data-path="fs-functions.html"><a href="fs-functions.html"><i class="fa fa-check"></i><b>12.3</b> fs函数介绍</a>
<ul>
<li class="chapter" data-level="12.3.1" data-path="fs-functions.html"><a href="fs-functions.html#fs-file-manipulation"><i class="fa fa-check"></i><b>12.3.1</b> 文件操作</a></li>
<li class="chapter" data-level="12.3.2" data-path="fs-functions.html"><a href="fs-functions.html#fs-dir-manipulation"><i class="fa fa-check"></i><b>12.3.2</b> 目录操作</a></li>
<li class="chapter" data-level="12.3.3" data-path="fs-functions.html"><a href="fs-functions.html#fs-link-manipulation"><i class="fa fa-check"></i><b>12.3.3</b> 链接操作</a></li>
<li class="chapter" data-level="12.3.4" data-path="fs-functions.html"><a href="fs-functions.html#fs-path-manipulation"><i class="fa fa-check"></i><b>12.3.4</b> 路径操作</a></li>
<li class="chapter" data-level="12.3.5" data-path="fs-functions.html"><a href="fs-functions.html#fs-help-manipulation"><i class="fa fa-check"></i><b>12.3.5</b> 辅助函数</a></li>
</ul></li>
<li class="chapter" data-level="12.4" data-path="file-base-fs-difference.html"><a href="file-base-fs-difference.html"><i class="fa fa-check"></i><b>12.4</b> base-fs-shell比较</a></li>
<li class="chapter" data-level="12.5" data-path="file-manipulation-reference-material.html"><a href="file-manipulation-reference-material.html"><i class="fa fa-check"></i><b>12.5</b> 参考资料</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://gitee.com/zhongyufei/Rbook" target="blank">gitee地址</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">商业数据分析师-R 语言数据处理</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="openxlsx:description" class="section level2" number="1.3">
<h2><span class="header-section-number">1.3</span> openxlsx</h2>
<p>openxlsx 包是当我需要定制输出 Excel 表格或报表时常用R包。目前该包的版本4.2.3，通过使用 Rcpp 加速，包的读写速度在 Excel 的百万级下是可接受状态，包的相关函数功能完善且简易好用，并且正在积极开发中，相信它以后功能会越来越强大。</p>
<p>项目官方地址:<a href="https://ycphs.github.io/openxlsx/index.html" class="uri">https://ycphs.github.io/openxlsx/index.html</a></p>
<p>openxlsx 主要优势：</p>
<ul>
<li>不依赖 java 环境</li>
<li>读写速度可接受</li>
<li>可设置条件格式，与 Excel 中『开始』选项卡的条件格式功能接近</li>
<li>可批量插入 ggplot2 图</li>
<li>可插入公式</li>
<li>可渲染大部分 Excel 格式，并且效率相比部分 python 包高效</li>
<li>可添加页眉页脚以及其他格式，方便直接打印</li>
<li>功能稳定可用并且在积极开发中</li>
</ul>
<p>版本信息查看</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="openxlsx-description.html#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">packageVersion</span>(<span class="st">&quot;openxlsx&quot;</span>)</span>
<span id="cb24-2"><a href="openxlsx-description.html#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &#39;4.2.3&#39;</span></span></code></pre></div>
<p>关于 openxlsx 更加详细的阐述:<a href="https://mp.weixin.qq.com/s/ZD0dJb0y8fsWGI1dCPh2mQ" class="uri">https://mp.weixin.qq.com/s/ZD0dJb0y8fsWGI1dCPh2mQ</a></p>
<div id="openxlsx:install" class="section level3" number="1.3.1">
<h3><span class="header-section-number">1.3.1</span> 安装</h3>
<p>从CRAN安装发行版</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="openxlsx-description.html#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 稳定版</span></span>
<span id="cb25-2"><a href="openxlsx-description.html#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="fu">install.packages</span>(<span class="st">&quot;openxlsx&quot;</span>, <span class="at">dependencies =</span> <span class="cn">TRUE</span>, <span class="at">repos =</span> <span class="st">&quot;https://mirrors.tuna.tsinghua.edu.cn/CRAN/&quot;</span>)</span></code></pre></div>
<p>从Github安装开发版</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="openxlsx-description.html#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">install.packages</span>(<span class="fu">c</span>(<span class="st">&quot;Rcpp&quot;</span>, <span class="st">&quot;devtools&quot;</span>), <span class="at">dependencies =</span> <span class="cn">TRUE</span>)</span>
<span id="cb26-2"><a href="openxlsx-description.html#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(devtools)</span>
<span id="cb26-3"><a href="openxlsx-description.html#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="fu">install_github</span>(<span class="st">&quot;ycphs/openxlsx&quot;</span>)</span></code></pre></div>
</div>
<div id="openxlsx:functions" class="section level3" number="1.3.2">
<h3><span class="header-section-number">1.3.2</span> 基础功能</h3>
<p>本文仅呈现基础功能部分，即读写 Excel 文件。其它功能，请查阅项目官方地址或微信公众号文章<a href="https://mp.weixin.qq.com/s/ZD0dJb0y8fsWGI1dCPh2mQ">R包-openxlsx-学习笔记</a></p>
<div id="openxlsx:read-function" class="section level4" number="1.3.2.1">
<h4><span class="header-section-number">1.3.2.1</span> 读取 Excel</h4>
<p><code>read.xlsx()</code>函数读取 Excel 文件。</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb27-1"><a href="openxlsx-description.html#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(openxlsx) </span>
<span id="cb27-2"><a href="openxlsx-description.html#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">read.xlsx</span>(<span class="st">&#39;./data/read-write/批量读写.xlsx&#39;</span>)</span>
<span id="cb27-3"><a href="openxlsx-description.html#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt;   name num</span></span>
<span id="cb27-4"><a href="openxlsx-description.html#cb27-4" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1    a   1</span></span>
<span id="cb27-5"><a href="openxlsx-description.html#cb27-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 2    a   2</span></span>
<span id="cb27-6"><a href="openxlsx-description.html#cb27-6" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 3    a   3</span></span>
<span id="cb27-7"><a href="openxlsx-description.html#cb27-7" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 4    b   4</span></span>
<span id="cb27-8"><a href="openxlsx-description.html#cb27-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 5    b   5</span></span>
<span id="cb27-9"><a href="openxlsx-description.html#cb27-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 6    b   6</span></span>
<span id="cb27-10"><a href="openxlsx-description.html#cb27-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 7    d   7</span></span>
<span id="cb27-11"><a href="openxlsx-description.html#cb27-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 8    d   8</span></span>
<span id="cb27-12"><a href="openxlsx-description.html#cb27-12" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 9    d   9</span></span></code></pre></div>
<p><code>read.xlsx()</code>参数如下：</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb28-1"><a href="openxlsx-description.html#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(openxlsx)</span>
<span id="cb28-2"><a href="openxlsx-description.html#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="fu">read.xlsx</span>(</span>
<span id="cb28-3"><a href="openxlsx-description.html#cb28-3" aria-hidden="true" tabindex="-1"></a>  xlsxFile,</span>
<span id="cb28-4"><a href="openxlsx-description.html#cb28-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">sheet =</span> <span class="dv">1</span>,</span>
<span id="cb28-5"><a href="openxlsx-description.html#cb28-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">startRow =</span> <span class="dv">1</span>,</span>
<span id="cb28-6"><a href="openxlsx-description.html#cb28-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">colNames =</span> <span class="cn">TRUE</span>,</span>
<span id="cb28-7"><a href="openxlsx-description.html#cb28-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">rowNames =</span> <span class="cn">FALSE</span>,</span>
<span id="cb28-8"><a href="openxlsx-description.html#cb28-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">detectDates =</span> <span class="cn">FALSE</span>,</span>
<span id="cb28-9"><a href="openxlsx-description.html#cb28-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">skipEmptyRows =</span> <span class="cn">TRUE</span>,</span>
<span id="cb28-10"><a href="openxlsx-description.html#cb28-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">skipEmptyCols =</span> <span class="cn">TRUE</span>,</span>
<span id="cb28-11"><a href="openxlsx-description.html#cb28-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">rows =</span> <span class="cn">NULL</span>,</span>
<span id="cb28-12"><a href="openxlsx-description.html#cb28-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">cols =</span> <span class="cn">NULL</span>,</span>
<span id="cb28-13"><a href="openxlsx-description.html#cb28-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">check.names =</span> <span class="cn">FALSE</span>,</span>
<span id="cb28-14"><a href="openxlsx-description.html#cb28-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep.names =</span> <span class="st">&quot;.&quot;</span>,</span>
<span id="cb28-15"><a href="openxlsx-description.html#cb28-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">namedRegion =</span> <span class="cn">NULL</span>,</span>
<span id="cb28-16"><a href="openxlsx-description.html#cb28-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">na.strings =</span> <span class="st">&quot;NA&quot;</span>,</span>
<span id="cb28-17"><a href="openxlsx-description.html#cb28-17" aria-hidden="true" tabindex="-1"></a>  <span class="at">fillMergedCells =</span> <span class="cn">FALSE</span></span>
<span id="cb28-18"><a href="openxlsx-description.html#cb28-18" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p>以上参数中需要注意：detecDates 参数，当你的 Excel 表格中带日期列时需要将参数设置为TRUE,不然将会把日期识别为数字读入。</p>
<p>fillMergedCells参数，当你读取的表格中存在合并单元格，将用值填充其他全部单元格,如下所示：</p>
<div class="figure">
<img src="https://gitee.com/zhongyufei/photo-bed/raw/pic/img/merge-cell-xlsx.png" alt="" />
<p class="caption">merge-cell</p>
</div>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb29-1"><a href="openxlsx-description.html#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">read.xlsx</span>(<span class="st">&#39;./test.xlsx&#39;</span>,<span class="at">detectDates =</span> <span class="cn">TRUE</span>,<span class="at">fillMergedCells =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>读取后如下所示：</p>
<div class="figure">
<img src="https://gitee.com/zhongyufei/photo-bed/raw/pic/img/R-read-merge-xlsx.png" alt="" />
<p class="caption">openxlsx-merge-xlsx</p>
</div>
<p>readWorkbook()也可以读取 Excel 表格数据，参数与read.xlsx基本一致。</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb30-1"><a href="openxlsx-description.html#cb30-1" aria-hidden="true" tabindex="-1"></a>xlsxFile <span class="ot">&lt;-</span> <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;readTest.xlsx&quot;</span>, <span class="at">package =</span> <span class="st">&quot;openxlsx&quot;</span>)</span>
<span id="cb30-2"><a href="openxlsx-description.html#cb30-2" aria-hidden="true" tabindex="-1"></a>df1 <span class="ot">&lt;-</span> <span class="fu">readWorkbook</span>(<span class="at">xlsxFile =</span> xlsxFile, <span class="at">sheet =</span> <span class="dv">1</span>)</span></code></pre></div>
</div>
<div id="openxlsx:write-function" class="section level4" number="1.3.2.2">
<h4><span class="header-section-number">1.3.2.2</span> 写入Excel</h4>
<p>数据清洗完后，或者是分组聚合完成，需要将结果从R导出到Excle，这时就利用<code>write.xlsx()</code>函数将结果数据集写入 Excel 中。</p>
<p>write.xlsx()函数写入</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb31-1"><a href="openxlsx-description.html#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(iris, <span class="at">file =</span> <span class="st">&quot;writeXLSX1.xlsx&quot;</span>, <span class="at">colNames =</span> <span class="cn">TRUE</span>, <span class="at">borders =</span> <span class="st">&quot;columns&quot;</span>)</span></code></pre></div>
<p>带格式输出</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb32-1"><a href="openxlsx-description.html#cb32-1" aria-hidden="true" tabindex="-1"></a>hs <span class="ot">&lt;-</span> <span class="fu">createStyle</span>(</span>
<span id="cb32-2"><a href="openxlsx-description.html#cb32-2" aria-hidden="true" tabindex="-1"></a>  <span class="at">textDecoration =</span> <span class="st">&quot;BOLD&quot;</span>, <span class="at">fontColour =</span> <span class="st">&quot;#FFFFFF&quot;</span>, <span class="at">fontSize =</span> <span class="dv">12</span>,</span>
<span id="cb32-3"><a href="openxlsx-description.html#cb32-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">fontName =</span> <span class="st">&quot;Arial Narrow&quot;</span>, <span class="at">fgFill =</span> <span class="st">&quot;#4F80BD&quot;</span></span>
<span id="cb32-4"><a href="openxlsx-description.html#cb32-4" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb32-5"><a href="openxlsx-description.html#cb32-5" aria-hidden="true" tabindex="-1"></a><span class="do">## Not run: </span></span>
<span id="cb32-6"><a href="openxlsx-description.html#cb32-6" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(iris,</span>
<span id="cb32-7"><a href="openxlsx-description.html#cb32-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">file =</span> <span class="st">&quot;writeXLSX3.xlsx&quot;</span>,</span>
<span id="cb32-8"><a href="openxlsx-description.html#cb32-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">colNames =</span> <span class="cn">TRUE</span>, <span class="at">borders =</span> <span class="st">&quot;rows&quot;</span>, <span class="at">headerStyle =</span> hs</span>
<span id="cb32-9"><a href="openxlsx-description.html#cb32-9" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p><a href="https://www.sioe.cn/yingyong/yanse-rgb-16/">#4F80BD</a>格式属于十六进制颜色码。</p>
</div>
</div>
<div id="定制格式输出" class="section level3" number="1.3.3">
<h3><span class="header-section-number">1.3.3</span> 定制格式输出</h3>
<p>openxlsx包有两套输出函数，<code>wrire.xlsx()</code>是其中一种，还有如下一种。</p>
<p>输出过程共分为四步，第一步创建workbook,第二步添加sheet,第三步写入数据，第四步保存workbook。在输出的过程中可以通过<code>addStyle()</code>、<code>createStyle()</code>或<code>conditionalFormatting</code>添加格式或条件格式。</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb33-1"><a href="openxlsx-description.html#cb33-1" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">a=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>,<span class="at">b=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>,<span class="at">d=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>)</span>
<span id="cb33-2"><a href="openxlsx-description.html#cb33-2" aria-hidden="true" tabindex="-1"></a>wb <span class="ot">&lt;-</span> <span class="fu">createWorkbook</span>(<span class="at">creator =</span> <span class="st">&#39;zhongyf&#39;</span>,<span class="at">title =</span> <span class="st">&#39;test&#39;</span>)</span>
<span id="cb33-3"><a href="openxlsx-description.html#cb33-3" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb,<span class="at">sheetName =</span> <span class="st">&#39;test&#39;</span>)</span>
<span id="cb33-4"><a href="openxlsx-description.html#cb33-4" aria-hidden="true" tabindex="-1"></a><span class="fu">writeDataTable</span>(wb,<span class="at">sheet =</span> <span class="st">&#39;test&#39;</span>,<span class="at">x =</span> df)</span>
<span id="cb33-5"><a href="openxlsx-description.html#cb33-5" aria-hidden="true" tabindex="-1"></a><span class="fu">saveWorkbook</span>(wb, <span class="st">&quot;test.xlsx&quot;</span>, <span class="at">overwrite =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>我们以上面四步输出的方式，查看包自带的例子。</p>
<ul>
<li><p>createWorkbook()</p></li>
<li><p>addWorksheet()</p></li>
<li><p>writeDataTable()</p></li>
<li><p>saveWorkbook()</p></li>
</ul>
<div class="sourceCode" id="cb34"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb34-1"><a href="openxlsx-description.html#cb34-1" aria-hidden="true" tabindex="-1"></a>wb <span class="ot">&lt;-</span> <span class="fu">createWorkbook</span>(<span class="st">&quot;Fred&quot;</span>)</span>
<span id="cb34-2"><a href="openxlsx-description.html#cb34-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-3"><a href="openxlsx-description.html#cb34-3" aria-hidden="true" tabindex="-1"></a><span class="do">## Add 3 worksheets</span></span>
<span id="cb34-4"><a href="openxlsx-description.html#cb34-4" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 1&quot;</span>)</span>
<span id="cb34-5"><a href="openxlsx-description.html#cb34-5" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 2&quot;</span>, <span class="at">gridLines =</span> <span class="cn">FALSE</span>)</span>
<span id="cb34-6"><a href="openxlsx-description.html#cb34-6" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 3&quot;</span>, <span class="at">tabColour =</span> <span class="st">&quot;red&quot;</span>)</span>
<span id="cb34-7"><a href="openxlsx-description.html#cb34-7" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 4&quot;</span>, <span class="at">gridLines =</span> <span class="cn">FALSE</span>, <span class="at">tabColour =</span> <span class="st">&quot;#4F81BD&quot;</span>)</span>
<span id="cb34-8"><a href="openxlsx-description.html#cb34-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-9"><a href="openxlsx-description.html#cb34-9" aria-hidden="true" tabindex="-1"></a><span class="do">## Headers and Footers</span></span>
<span id="cb34-10"><a href="openxlsx-description.html#cb34-10" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 5&quot;</span>,</span>
<span id="cb34-11"><a href="openxlsx-description.html#cb34-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="fu">c</span>(<span class="st">&quot;ODD HEAD LEFT&quot;</span>, <span class="st">&quot;ODD HEAD CENTER&quot;</span>, <span class="st">&quot;ODD HEAD RIGHT&quot;</span>),</span>
<span id="cb34-12"><a href="openxlsx-description.html#cb34-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">footer =</span> <span class="fu">c</span>(<span class="st">&quot;ODD FOOT RIGHT&quot;</span>, <span class="st">&quot;ODD FOOT CENTER&quot;</span>, <span class="st">&quot;ODD FOOT RIGHT&quot;</span>),</span>
<span id="cb34-13"><a href="openxlsx-description.html#cb34-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">evenHeader =</span> <span class="fu">c</span>(<span class="st">&quot;EVEN HEAD LEFT&quot;</span>, <span class="st">&quot;EVEN HEAD CENTER&quot;</span>, <span class="st">&quot;EVEN HEAD RIGHT&quot;</span>),</span>
<span id="cb34-14"><a href="openxlsx-description.html#cb34-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">evenFooter =</span> <span class="fu">c</span>(<span class="st">&quot;EVEN FOOT RIGHT&quot;</span>, <span class="st">&quot;EVEN FOOT CENTER&quot;</span>, <span class="st">&quot;EVEN FOOT RIGHT&quot;</span>),</span>
<span id="cb34-15"><a href="openxlsx-description.html#cb34-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstHeader =</span> <span class="fu">c</span>(<span class="st">&quot;TOP&quot;</span>, <span class="st">&quot;OF FIRST&quot;</span>, <span class="st">&quot;PAGE&quot;</span>),</span>
<span id="cb34-16"><a href="openxlsx-description.html#cb34-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstFooter =</span> <span class="fu">c</span>(<span class="st">&quot;BOTTOM&quot;</span>, <span class="st">&quot;OF FIRST&quot;</span>, <span class="st">&quot;PAGE&quot;</span>)</span>
<span id="cb34-17"><a href="openxlsx-description.html#cb34-17" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb34-18"><a href="openxlsx-description.html#cb34-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-19"><a href="openxlsx-description.html#cb34-19" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 6&quot;</span>,</span>
<span id="cb34-20"><a href="openxlsx-description.html#cb34-20" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="fu">c</span>(<span class="st">&quot;&amp;[Date]&quot;</span>, <span class="st">&quot;ALL HEAD CENTER 2&quot;</span>, <span class="st">&quot;&amp;[Page] / &amp;[Pages]&quot;</span>),</span>
<span id="cb34-21"><a href="openxlsx-description.html#cb34-21" aria-hidden="true" tabindex="-1"></a>  <span class="at">footer =</span> <span class="fu">c</span>(<span class="st">&quot;&amp;[Path]&amp;[File]&quot;</span>, <span class="cn">NA</span>, <span class="st">&quot;&amp;[Tab]&quot;</span>),</span>
<span id="cb34-22"><a href="openxlsx-description.html#cb34-22" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstHeader =</span> <span class="fu">c</span>(<span class="cn">NA</span>, <span class="st">&quot;Center Header of First Page&quot;</span>, <span class="cn">NA</span>),</span>
<span id="cb34-23"><a href="openxlsx-description.html#cb34-23" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstFooter =</span> <span class="fu">c</span>(<span class="cn">NA</span>, <span class="st">&quot;Center Footer of First Page&quot;</span>, <span class="cn">NA</span>)</span>
<span id="cb34-24"><a href="openxlsx-description.html#cb34-24" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb34-25"><a href="openxlsx-description.html#cb34-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-26"><a href="openxlsx-description.html#cb34-26" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 7&quot;</span>,</span>
<span id="cb34-27"><a href="openxlsx-description.html#cb34-27" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="fu">c</span>(<span class="st">&quot;ALL HEAD LEFT 2&quot;</span>, <span class="st">&quot;ALL HEAD CENTER 2&quot;</span>, <span class="st">&quot;ALL HEAD RIGHT 2&quot;</span>),</span>
<span id="cb34-28"><a href="openxlsx-description.html#cb34-28" aria-hidden="true" tabindex="-1"></a>  <span class="at">footer =</span> <span class="fu">c</span>(<span class="st">&quot;ALL FOOT RIGHT 2&quot;</span>, <span class="st">&quot;ALL FOOT CENTER 2&quot;</span>, <span class="st">&quot;ALL FOOT RIGHT 2&quot;</span>)</span>
<span id="cb34-29"><a href="openxlsx-description.html#cb34-29" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb34-30"><a href="openxlsx-description.html#cb34-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-31"><a href="openxlsx-description.html#cb34-31" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb, <span class="st">&quot;Sheet 8&quot;</span>,</span>
<span id="cb34-32"><a href="openxlsx-description.html#cb34-32" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstHeader =</span> <span class="fu">c</span>(<span class="st">&quot;FIRST ONLY L&quot;</span>, <span class="cn">NA</span>, <span class="st">&quot;FIRST ONLY R&quot;</span>),</span>
<span id="cb34-33"><a href="openxlsx-description.html#cb34-33" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstFooter =</span> <span class="fu">c</span>(<span class="st">&quot;FIRST ONLY L&quot;</span>, <span class="cn">NA</span>, <span class="st">&quot;FIRST ONLY R&quot;</span>)</span>
<span id="cb34-34"><a href="openxlsx-description.html#cb34-34" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb34-35"><a href="openxlsx-description.html#cb34-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-36"><a href="openxlsx-description.html#cb34-36" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(wb,<span class="st">&#39;dataframe&#39;</span>)</span>
<span id="cb34-37"><a href="openxlsx-description.html#cb34-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-38"><a href="openxlsx-description.html#cb34-38" aria-hidden="true" tabindex="-1"></a><span class="do">## Need data on worksheet to see all headers and footers</span></span>
<span id="cb34-39"><a href="openxlsx-description.html#cb34-39" aria-hidden="true" tabindex="-1"></a><span class="fu">writeData</span>(wb, <span class="at">sheet =</span> <span class="dv">5</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">400</span>)</span>
<span id="cb34-40"><a href="openxlsx-description.html#cb34-40" aria-hidden="true" tabindex="-1"></a><span class="fu">writeData</span>(wb, <span class="at">sheet =</span> <span class="dv">6</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">400</span>)</span>
<span id="cb34-41"><a href="openxlsx-description.html#cb34-41" aria-hidden="true" tabindex="-1"></a><span class="fu">writeData</span>(wb, <span class="at">sheet =</span> <span class="dv">7</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">400</span>)</span>
<span id="cb34-42"><a href="openxlsx-description.html#cb34-42" aria-hidden="true" tabindex="-1"></a><span class="fu">writeData</span>(wb, <span class="at">sheet =</span> <span class="dv">8</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">400</span>)</span>
<span id="cb34-43"><a href="openxlsx-description.html#cb34-43" aria-hidden="true" tabindex="-1"></a><span class="fu">writeDataTable</span>(wb,<span class="at">sheet =</span> <span class="st">&#39;dataframe&#39;</span>,iris)</span>
<span id="cb34-44"><a href="openxlsx-description.html#cb34-44" aria-hidden="true" tabindex="-1"></a><span class="do">## Save workbook</span></span>
<span id="cb34-45"><a href="openxlsx-description.html#cb34-45" aria-hidden="true" tabindex="-1"></a><span class="do">## Not run: </span></span>
<span id="cb34-46"><a href="openxlsx-description.html#cb34-46" aria-hidden="true" tabindex="-1"></a><span class="fu">saveWorkbook</span>(wb, <span class="st">&quot;addWorksheetExample.xlsx&quot;</span>, <span class="at">overwrite =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="函数参数" class="section level3" number="1.3.4">
<h3><span class="header-section-number">1.3.4</span> 函数参数</h3>
<p>本小节主要讲<code>createWorkbook()</code>，<code>addWorksheet()</code>,<code>writeDataTable()</code>,<code>saveWorkbook()</code>四个函数的参数以及用法。</p>
<ul>
<li>createWorkbook</li>
</ul>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb35-1"><a href="openxlsx-description.html#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="fu">createWorkbook</span>(</span>
<span id="cb35-2"><a href="openxlsx-description.html#cb35-2" aria-hidden="true" tabindex="-1"></a>  <span class="at">creator =</span> <span class="fu">ifelse</span>(.Platform<span class="sc">$</span>OS.type <span class="sc">==</span> <span class="st">&quot;windows&quot;</span>, <span class="fu">Sys.getenv</span>(<span class="st">&quot;USERNAME&quot;</span>),</span>
<span id="cb35-3"><a href="openxlsx-description.html#cb35-3" aria-hidden="true" tabindex="-1"></a>    <span class="fu">Sys.getenv</span>(<span class="st">&quot;USER&quot;</span>)),</span>
<span id="cb35-4"><a href="openxlsx-description.html#cb35-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb35-5"><a href="openxlsx-description.html#cb35-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">subject =</span> <span class="cn">NULL</span>,</span>
<span id="cb35-6"><a href="openxlsx-description.html#cb35-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">category =</span> <span class="cn">NULL</span></span>
<span id="cb35-7"><a href="openxlsx-description.html#cb35-7" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<div class="sourceCode" id="cb36"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb36-1"><a href="openxlsx-description.html#cb36-1" aria-hidden="true" tabindex="-1"></a>wb <span class="ot">&lt;-</span> <span class="fu">createWorkbook</span>(</span>
<span id="cb36-2"><a href="openxlsx-description.html#cb36-2" aria-hidden="true" tabindex="-1"></a>  <span class="at">creator =</span> <span class="st">&quot;宇飞的世界&quot;</span>,</span>
<span id="cb36-3"><a href="openxlsx-description.html#cb36-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">title =</span> <span class="st">&quot;标题&quot;</span>,</span>
<span id="cb36-4"><a href="openxlsx-description.html#cb36-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">subject =</span> <span class="st">&quot;主题&quot;</span>,</span>
<span id="cb36-5"><a href="openxlsx-description.html#cb36-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">category =</span> <span class="st">&quot;类别目录&quot;</span></span>
<span id="cb36-6"><a href="openxlsx-description.html#cb36-6" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p>在win系统上右击 Excel 文件属性，点击详细信息：</p>
<div class="figure">
<img src="picture/read-write/open-wb-attribute.png" alt="" />
<p class="caption">win-excel-attribute</p>
</div>
<ul>
<li>addWorksheet</li>
</ul>
<p><code>addWorksheet()</code>函数添加sheet。</p>
<div class="sourceCode" id="cb37"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb37-1"><a href="openxlsx-description.html#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="fu">addWorksheet</span>(</span>
<span id="cb37-2"><a href="openxlsx-description.html#cb37-2" aria-hidden="true" tabindex="-1"></a>  wb,</span>
<span id="cb37-3"><a href="openxlsx-description.html#cb37-3" aria-hidden="true" tabindex="-1"></a>  sheetName,</span>
<span id="cb37-4"><a href="openxlsx-description.html#cb37-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">gridLines =</span> <span class="cn">TRUE</span>,</span>
<span id="cb37-5"><a href="openxlsx-description.html#cb37-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">tabColour =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-6"><a href="openxlsx-description.html#cb37-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">zoom =</span> <span class="dv">100</span>,</span>
<span id="cb37-7"><a href="openxlsx-description.html#cb37-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-8"><a href="openxlsx-description.html#cb37-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">footer =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-9"><a href="openxlsx-description.html#cb37-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">evenHeader =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-10"><a href="openxlsx-description.html#cb37-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">evenFooter =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-11"><a href="openxlsx-description.html#cb37-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstHeader =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-12"><a href="openxlsx-description.html#cb37-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstFooter =</span> <span class="cn">NULL</span>,</span>
<span id="cb37-13"><a href="openxlsx-description.html#cb37-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">visible =</span> <span class="cn">TRUE</span>,</span>
<span id="cb37-14"><a href="openxlsx-description.html#cb37-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">paperSize =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.paperSize&quot;</span>, <span class="at">default =</span> <span class="dv">9</span>),</span>
<span id="cb37-15"><a href="openxlsx-description.html#cb37-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">orientation =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.orientation&quot;</span>, <span class="at">default =</span> <span class="st">&quot;portrait&quot;</span>),</span>
<span id="cb37-16"><a href="openxlsx-description.html#cb37-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">vdpi =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.vdpi&quot;</span>, <span class="at">default =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.dpi&quot;</span>, <span class="at">default =</span> <span class="dv">300</span>)),</span>
<span id="cb37-17"><a href="openxlsx-description.html#cb37-17" aria-hidden="true" tabindex="-1"></a>  <span class="at">hdpi =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.hdpi&quot;</span>, <span class="at">default =</span> <span class="fu">getOption</span>(<span class="st">&quot;openxlsx.dpi&quot;</span>, <span class="at">default =</span> <span class="dv">300</span>))</span>
<span id="cb37-18"><a href="openxlsx-description.html#cb37-18" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p><code>addWorksheet()</code>参数解释如下：</p>
<div class="sourceCode" id="cb38"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb38-1"><a href="openxlsx-description.html#cb38-1" aria-hidden="true" tabindex="-1"></a>gridLines参数：表格中是否有网格线，在Excle『视图』选项卡下面的网格线去除打勾的效果一致</span>
<span id="cb38-2"><a href="openxlsx-description.html#cb38-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-3"><a href="openxlsx-description.html#cb38-3" aria-hidden="true" tabindex="-1"></a>tabColour参数：输出表格sheet标签颜色</span>
<span id="cb38-4"><a href="openxlsx-description.html#cb38-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-5"><a href="openxlsx-description.html#cb38-5" aria-hidden="true" tabindex="-1"></a>zoom：发大缩小，默认是100，可选范围10<span class="dv">-400</span></span>
<span id="cb38-6"><a href="openxlsx-description.html#cb38-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-7"><a href="openxlsx-description.html#cb38-7" aria-hidden="true" tabindex="-1"></a>header<span class="sc">:</span>页眉 长度为3的字符向量，左、中、右三个位置，用Na可跳过一位置，以下页眉页脚相同。</span>
<span id="cb38-8"><a href="openxlsx-description.html#cb38-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-9"><a href="openxlsx-description.html#cb38-9" aria-hidden="true" tabindex="-1"></a>footer<span class="sc">:</span> 页脚</span>
<span id="cb38-10"><a href="openxlsx-description.html#cb38-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-11"><a href="openxlsx-description.html#cb38-11" aria-hidden="true" tabindex="-1"></a>evenHeader<span class="sc">:</span> 每页页眉</span>
<span id="cb38-12"><a href="openxlsx-description.html#cb38-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-13"><a href="openxlsx-description.html#cb38-13" aria-hidden="true" tabindex="-1"></a>evenFooter<span class="sc">:</span> 每页页脚</span>
<span id="cb38-14"><a href="openxlsx-description.html#cb38-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-15"><a href="openxlsx-description.html#cb38-15" aria-hidden="true" tabindex="-1"></a>firstHeader<span class="sc">:</span> 第一页页眉</span>
<span id="cb38-16"><a href="openxlsx-description.html#cb38-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-17"><a href="openxlsx-description.html#cb38-17" aria-hidden="true" tabindex="-1"></a>firstFooter<span class="sc">:</span> 第一页页脚</span>
<span id="cb38-18"><a href="openxlsx-description.html#cb38-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-19"><a href="openxlsx-description.html#cb38-19" aria-hidden="true" tabindex="-1"></a>visible<span class="sc">:</span>sheet是否隐藏，如果为否sheet将被隐藏</span>
<span id="cb38-20"><a href="openxlsx-description.html#cb38-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-21"><a href="openxlsx-description.html#cb38-21" aria-hidden="true" tabindex="-1"></a>paperSize<span class="sc">:</span>页面大小,详见 ?pageSetup </span>
<span id="cb38-22"><a href="openxlsx-description.html#cb38-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-23"><a href="openxlsx-description.html#cb38-23" aria-hidden="true" tabindex="-1"></a>orientation<span class="sc">:</span>One of <span class="st">&quot;portrait&quot;</span> or <span class="st">&quot;landscape&quot;</span> 不清楚干嘛用</span>
<span id="cb38-24"><a href="openxlsx-description.html#cb38-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-25"><a href="openxlsx-description.html#cb38-25" aria-hidden="true" tabindex="-1"></a>vdpi<span class="sc">:</span> 屏幕分辨率 默认值即可，不用调整</span>
<span id="cb38-26"><a href="openxlsx-description.html#cb38-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-27"><a href="openxlsx-description.html#cb38-27" aria-hidden="true" tabindex="-1"></a>hdpi<span class="sc">:</span> 屏幕分辨率 默认值即可，不用调整</span></code></pre></div>
<ul>
<li>writeDataTable</li>
</ul>
<p>writeDataTable()函数将data.frame写入 Excel 。</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb39-1"><a href="openxlsx-description.html#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="fu">writeDataTable</span>(</span>
<span id="cb39-2"><a href="openxlsx-description.html#cb39-2" aria-hidden="true" tabindex="-1"></a>  wb,</span>
<span id="cb39-3"><a href="openxlsx-description.html#cb39-3" aria-hidden="true" tabindex="-1"></a>  sheet,</span>
<span id="cb39-4"><a href="openxlsx-description.html#cb39-4" aria-hidden="true" tabindex="-1"></a>  x,</span>
<span id="cb39-5"><a href="openxlsx-description.html#cb39-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">startCol =</span> <span class="dv">1</span>,</span>
<span id="cb39-6"><a href="openxlsx-description.html#cb39-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">startRow =</span> <span class="dv">1</span>,</span>
<span id="cb39-7"><a href="openxlsx-description.html#cb39-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">xy =</span> <span class="cn">NULL</span>,</span>
<span id="cb39-8"><a href="openxlsx-description.html#cb39-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">colNames =</span> <span class="cn">TRUE</span>,</span>
<span id="cb39-9"><a href="openxlsx-description.html#cb39-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">rowNames =</span> <span class="cn">FALSE</span>,</span>
<span id="cb39-10"><a href="openxlsx-description.html#cb39-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">tableStyle =</span> <span class="st">&quot;TableStyleLight9&quot;</span>,</span>
<span id="cb39-11"><a href="openxlsx-description.html#cb39-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">tableName =</span> <span class="cn">NULL</span>,</span>
<span id="cb39-12"><a href="openxlsx-description.html#cb39-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">headerStyle =</span> <span class="cn">NULL</span>,</span>
<span id="cb39-13"><a href="openxlsx-description.html#cb39-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">withFilter =</span> <span class="cn">TRUE</span>,</span>
<span id="cb39-14"><a href="openxlsx-description.html#cb39-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">keepNA =</span> <span class="cn">FALSE</span>,</span>
<span id="cb39-15"><a href="openxlsx-description.html#cb39-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">na.string =</span> <span class="cn">NULL</span>,</span>
<span id="cb39-16"><a href="openxlsx-description.html#cb39-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">&quot;, &quot;</span>,</span>
<span id="cb39-17"><a href="openxlsx-description.html#cb39-17" aria-hidden="true" tabindex="-1"></a>  <span class="at">stack =</span> <span class="cn">FALSE</span>,</span>
<span id="cb39-18"><a href="openxlsx-description.html#cb39-18" aria-hidden="true" tabindex="-1"></a>  <span class="at">firstColumn =</span> <span class="cn">FALSE</span>,</span>
<span id="cb39-19"><a href="openxlsx-description.html#cb39-19" aria-hidden="true" tabindex="-1"></a>  <span class="at">lastColumn =</span> <span class="cn">FALSE</span>,</span>
<span id="cb39-20"><a href="openxlsx-description.html#cb39-20" aria-hidden="true" tabindex="-1"></a>  <span class="at">bandedRows =</span> <span class="cn">TRUE</span>,</span>
<span id="cb39-21"><a href="openxlsx-description.html#cb39-21" aria-hidden="true" tabindex="-1"></a>  <span class="at">bandedCols =</span> <span class="cn">FALSE</span></span>
<span id="cb39-22"><a href="openxlsx-description.html#cb39-22" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p><code>writeDataTable()</code>参数解释如下：</p>
<div class="sourceCode" id="cb40"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb40-1"><a href="openxlsx-description.html#cb40-1" aria-hidden="true" tabindex="-1"></a>wb<span class="sc">:</span>即<span class="fu">createWorkbook</span>()函数创建的workbook对象</span>
<span id="cb40-2"><a href="openxlsx-description.html#cb40-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-3"><a href="openxlsx-description.html#cb40-3" aria-hidden="true" tabindex="-1"></a>sheet<span class="sc">:</span>将输入写入的sheet名，由<span class="fu">addWorksheet</span>()函数创建</span>
<span id="cb40-4"><a href="openxlsx-description.html#cb40-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-5"><a href="openxlsx-description.html#cb40-5" aria-hidden="true" tabindex="-1"></a>x <span class="sc">:</span> a data.frame</span>
<span id="cb40-6"><a href="openxlsx-description.html#cb40-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-7"><a href="openxlsx-description.html#cb40-7" aria-hidden="true" tabindex="-1"></a>startCol<span class="sc">:</span> 从哪一列开始写入,接受数字</span>
<span id="cb40-8"><a href="openxlsx-description.html#cb40-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-9"><a href="openxlsx-description.html#cb40-9" aria-hidden="true" tabindex="-1"></a>startRow：从哪一行开始写入，接受数字</span>
<span id="cb40-10"><a href="openxlsx-description.html#cb40-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-11"><a href="openxlsx-description.html#cb40-11" aria-hidden="true" tabindex="-1"></a>xy<span class="sc">:</span> 指定开始行以及开始列的向量，xy <span class="ot">=</span> <span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">3</span>)即从2列3行位置开始写入</span>
<span id="cb40-12"><a href="openxlsx-description.html#cb40-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-13"><a href="openxlsx-description.html#cb40-13" aria-hidden="true" tabindex="-1"></a>colNames<span class="sc">:</span> 如果TRUE,列名写入</span>
<span id="cb40-14"><a href="openxlsx-description.html#cb40-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-15"><a href="openxlsx-description.html#cb40-15" aria-hidden="true" tabindex="-1"></a>rowNames<span class="sc">:</span> 如果TRUE,行名写入</span>
<span id="cb40-16"><a href="openxlsx-description.html#cb40-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-17"><a href="openxlsx-description.html#cb40-17" aria-hidden="true" tabindex="-1"></a>tableStyle<span class="sc">:</span>一些表格样式，在中文版Excle『开始』选项卡下面的套用表格格式，可以使用预定义的表格样式</span>
<span id="cb40-18"><a href="openxlsx-description.html#cb40-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-19"><a href="openxlsx-description.html#cb40-19" aria-hidden="true" tabindex="-1"></a>tableName<span class="sc">:</span>workbook中的表中，表名必须是唯一的，熟悉Power Pivot的人应该很清晰“表”概念</span>
<span id="cb40-20"><a href="openxlsx-description.html#cb40-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-21"><a href="openxlsx-description.html#cb40-21" aria-hidden="true" tabindex="-1"></a>headerStyle<span class="sc">:</span>自定义列样式应用,用<span class="fu">createStyle</span>()函数创建</span>
<span id="cb40-22"><a href="openxlsx-description.html#cb40-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-23"><a href="openxlsx-description.html#cb40-23" aria-hidden="true" tabindex="-1"></a>withFilter<span class="sc">:</span> 在第一行是否有筛选</span>
<span id="cb40-24"><a href="openxlsx-description.html#cb40-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-25"><a href="openxlsx-description.html#cb40-25" aria-hidden="true" tabindex="-1"></a>keepNA<span class="sc">:</span>如果TRUE,NA值转化为<span class="co">#NA，如果否，变为空</span></span>
<span id="cb40-26"><a href="openxlsx-description.html#cb40-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-27"><a href="openxlsx-description.html#cb40-27" aria-hidden="true" tabindex="-1"></a>na.string <span class="sc">:</span>如果参数不是NULL,如果keepNA是TRUE,NA将会在 Excel 中转为该参数指定的字符</span>
<span id="cb40-28"><a href="openxlsx-description.html#cb40-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-29"><a href="openxlsx-description.html#cb40-29" aria-hidden="true" tabindex="-1"></a>sep：列表列的分隔符，默认为<span class="st">&quot;,&quot;</span></span>
<span id="cb40-30"><a href="openxlsx-description.html#cb40-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-31"><a href="openxlsx-description.html#cb40-31" aria-hidden="true" tabindex="-1"></a>stack <span class="sc">:</span>详情请参照函数使用</span>
<span id="cb40-32"><a href="openxlsx-description.html#cb40-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-33"><a href="openxlsx-description.html#cb40-33" aria-hidden="true" tabindex="-1"></a>firstColumn<span class="sc">:</span>logical. If <span class="cn">TRUE</span>, the first column is bold</span>
<span id="cb40-34"><a href="openxlsx-description.html#cb40-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-35"><a href="openxlsx-description.html#cb40-35" aria-hidden="true" tabindex="-1"></a>lastColumn <span class="sc">:</span>logical. If <span class="cn">TRUE</span>, the last column is bold</span>
<span id="cb40-36"><a href="openxlsx-description.html#cb40-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-37"><a href="openxlsx-description.html#cb40-37" aria-hidden="true" tabindex="-1"></a>bandedRows<span class="sc">:</span>logical. If <span class="cn">TRUE</span>, rows are colour banded 即行线,默认为TRUE</span>
<span id="cb40-38"><a href="openxlsx-description.html#cb40-38" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-39"><a href="openxlsx-description.html#cb40-39" aria-hidden="true" tabindex="-1"></a>bandedCols<span class="sc">:</span>logical. If <span class="cn">TRUE</span>, the columns are colour banded 即列线 ,默认为TRUE</span></code></pre></div>
<ul>
<li>saveWorkbook</li>
</ul>
<div class="sourceCode" id="cb41"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb41-1"><a href="openxlsx-description.html#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="fu">saveWorkbook</span>(wb, file, <span class="at">overwrite =</span> <span class="cn">FALSE</span>, <span class="at">returnValue =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
<p>参数较为简单，wb即上文中的workbook对象，file即输出的文件名，overwrite即如果存在是否覆盖，returnValue如果设置为TRUE，返回TRUE代表保存成功</p>
</div>
<div id="总结" class="section level3" number="1.3.5">
<h3><span class="header-section-number">1.3.5</span> 总结</h3>
<p>openxlsx包功能较为强大，更多详细用法大家可自行探索，或关注我的语雀笔记，笔记会不定期持续更新。</p>
<p>R包openxlsx学习笔记:<a href="https://www.yuque.com/docs/share/7a768e6f-95e0-417c-a9b5-dfc8862dc6be?#" class="uri">https://www.yuque.com/docs/share/7a768e6f-95e0-417c-a9b5-dfc8862dc6be?#</a></p>
<p>语雀个人主页:<a href="https://www.yuque.com/zyufei" class="uri">https://www.yuque.com/zyufei</a></p>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="writexl.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="readr-package.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["Data-Handling-in-R.pdf", "Data-Handling-in-R.epub"],
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
